package com.dycn.controller;

import com.dycn.model.Activitys;
import com.dycn.model.ActivitysVo;
import com.dycn.service.ActivitysService;
import com.dycn.util.AppResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("activity")
public class ActivityController {

    @Autowired
    ActivitysService activitysService;
    @ResponseBody
    @RequestMapping("listActivitys")
    public AppResultData listActivitys(int page, Integer type, HttpServletRequest httpServletRequest){
        return  activitysService.listActivitys(page,type,httpServletRequest);
    }
    @ResponseBody
    @RequestMapping("saveOrUpdate")
    public  AppResultData saveOrUpdate(ActivitysVo activitysVo){
        return  activitysService.saveOrUpdate(activitysVo.toActivitys());
    }


    @RequestMapping("detail")
    public  String detail(Model model,Integer id){
        if(id!=null)
        model.addAttribute("data",activitysService.selectByPrimaryKey(id).toActivitysVo());
        return  "/role/addactivitys";
    }


    @ResponseBody
    @RequestMapping("del")
    public  AppResultData del(Integer id){
        return  activitysService.del(id);
    }

    @ResponseBody
    @RequestMapping("fabu")
    public  AppResultData fabu(Integer id){
        Activitys activitys=activitysService.selectByPrimaryKey(id);
        activitys.setStatus(activitys.getStatus()==0?1:0);
        activitysService.updateByPrimaryKeySelective(activitys);
        return  AppResultData.successMessage("成功");
    }
}
